{% extends 'base.html' %}
{% load filters %}
{% load tags %}
{% block title %}{{ post.title }}{% endblock %}

{% block description %}{% space_line_less %}
    {% if post.summary %}
        {{ post.summary|striptags|addslashes }}
    {% else %}
        {{ post.content|striptags|slice:"120"|addslashes }}
    {% endif %}
{% endspace_line_less %}{% endblock %}

{% block content %}

  <div id="postslist">
        <div class="post" id="post-{{ post.key }}">
      <div class="title">
        <h2><a href="{{ settings.BASE_URL }}/p/{{ post.key }}/" rel="bookmark" title="Permanent Link {{ post.title|addslashes }}">{{ post.title }}</a></h2>

        <small>Posted by {{ settings.BLOG_AUTHOR }} on {{ post.add_time|format_time }}.</small>
      </div>
      <div class="entry">
        {{ post.content|process_html_show|safe }}
      </div>
      <p class="postmeta"></p>

      <div class="post-nav">
        <span class="previous">
        {% if pre_post %}
        <a href="{{ settings.BASE_URL }}/p/{{ pre_post.key }}/">{{ pre_post.title }}</a>
        {% endif %}
        </span>
        <span class="next">
        {% if next_post %}
        <a href="{{ settings.BASE_URL }}/p/{{ next_post.key }}/">{{ next_post.title }}</a>
        {% endif %}
        </span>
        <br clear="all"/>
      </div>
    </div>
    <!-- You can start editing here. -->
<h3 id="comments">{% if post.comment_count %}{{ post.comment_count }}{% else %}No{% endif %} Responses to &#8220;{{ post.title }}&#8221;</h3>

<p class="comments">&#187; You can <a href="#respond">leave a response</a> .</p>

<ol class="commentlist">
  {% for comment in comment_list %}
  <li class="alt" id="comment-{{ forloop.counter }}">
    <div class="list">
            <div class="gravatar">
            <img alt='{{ comment.nickname }}' src='http://www.gravatar.com/avatar/{{ comment.email|md5 }}?s=32' class='avatar avatar-32 photo avatar-default' height='32' width='32' />
            </div>

            <small class="commentmetadata">
            <a href="#comment-{{ forloop.counter }}" title="">{{ comment.add_time|format_time }}</a>

            </small>

      <cite>
      <a href='{{ comment.link|default:"" }}' rel='external nofollow' class='url'>{{ comment.nickname }}</a>
      </cite> Says:
            <p>{{ comment.content|force_escape|cover_space|linebreaks|safe }}</p>
    </div>
  </li>
  {% endfor %}

</ol>

<script type="text/javascript" src="{{ MEDIA_URL }}/js/xhconn.js"></script>
<script type="text/javascript">
<!--
    function encode_args(args){
        var s = '';
        for(var k in args){
            if(s) s+='&'
            s += (encodeURIComponent(k) + '=' + encodeURIComponent(args[k]))
        }
        return s;
    }
    
    function a(id){
        return document.getElementById(id)
    }
    function _add_comment(form){
        var myConn = new XHConn();
        var fnWhenDone = function (oXML) { 
            var res = eval('(' + oXML.responseText + ')');
            if(res.state == 'err'){
                alert(res.msg);
            }
            else if(res.state == 'ok'){
                //alert(res.msg);
                location.reload();
            }
            else{
                alert(res.state);
            }
            a('submit_span').style.display = '';
            a('submiting_span').style.display = 'none';
        };
        var args = encode_args({
            'nickname': form['nickname'].value,
            'email': form['email'].value,
            'content': form['comment'].value,
            'link': form['link'].value,
            'post_key': form['post_key'].value
        });
        a('submit_span').style.display = 'none';
        a('submiting_span').style.display = '';
        myConn.connect("{{ settings.BASE_URL }}/add_comment/", "POST", args, fnWhenDone);
    }
    function add_comment(form){
        try{
            _add_comment(form)
        }
        catch(e){
            alert(e.message)
        }
    }
//-->
</script>
<h3 id="respond">Leave a Reply</h3>
  <form onsubmit="add_comment(this); return false;" action="{{ settings.BASE_URL }}/add_comment/" method="post" id="commentform" class="reply">
    <p>
    <input type="text" name="nickname" id="nickname" value="{% if user %}{{ user.nickname|addslashes }}{% endif %}" size="22" tabindex="1" class="text" />
    <label for="nickname"><small>名字(required)</small></label>

  </p>
  <p>
    <input {% if user %}value="{{ user.email }}" readonly="true"{% endif %} type="text" name="email" id="email" value="" size="22" tabindex="2" class="text" />
    <label for="email"><small>邮箱 (will not be published)(required)</small></label>
  </p>
  <p>
    <input type="text" name="link" id="link" {% if user %}value="{{ user.link|default:"" }}"{% endif %} size="22" tabindex="3" class="text" />
    <label for="link"><small>网址</small></label>

  </p>
    
  <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
  <p>
    <input name="submit_span" type="submit" id="submit_span" tabindex="5" value=" "  class="comm_submit" onmousedown="this.className='comm_submit_down'" onmousemove="this.className='comm_submit_move'" onmouseout="this.className='comm_submit'"/>
    <input type="hidden" name="post_key" value="{{ post.key }}" />
    <span id="submiting_span" style="display: none">提交中...</span>
  </p>
  </form>

</div>
  

{% endblock %} 